<template>
	<!--供应商信息-物资供应商列表-->
	<a-card :bordered="false">
		<!-- 查询区域 -->
		<div class="table-page-search-wrapper">
			<a-form layout="inline" @keyup.enter.native="searchQuery">
				<a-row :gutter="24">
					<a-col :md="5" :sm="12">
						<a-form-item label="公司名称">
							<a-input placeholder="请输入公司名称" v-model="queryParam.supplierName"></a-input>
						</a-form-item>
					</a-col>
					<a-col :md="5" :sm="12">
						<a-form-item label="评分">
							<div style="display: flex;align-content: center;">
								<a-input placeholder="请输入最小值" v-model="queryParam.scoreMin" style="width:calc(50% - 10px);"></a-input>
								<div style="width: 20px;text-align: center;">~</div>
								<a-input placeholder="请输入最大值" v-model="queryParam.scoreMax" style="width:calc(50% - 10px)"></a-input>
							</div>
							
						</a-form-item>
					</a-col>
					<a-col :xl="5" :lg="8" :md="11" :sm="24">
						<a-form-item label="类型">
							<a-select :options="statusList" placeholder="请选择状态" v-model="queryParam.rateeType"></a-select>
						</a-form-item>
					</a-col>
					<a-col :xl="8" :lg="8" :md="11" :sm="24">
						<a-form-item label="评价时间">
							<j-date v-model="queryParam.queryStartTime" :showTime="true" date-format="YYYY-MM-DD "
								style="width: 25%" placeholder="请选择开始时间"></j-date>
							<span style="width: 10px">~</span>
							<j-date v-model="queryParam.queryEndTime" :showTime="true" date-format="YYYY-MM-DD"
								style="width: 25%" placeholder="请选择结束时间"></j-date>
						</a-form-item>
					</a-col>
					<a-col :md="6" :sm="8">
						<span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
							<a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
							<a-button type="primary" @click="searchReset" icon="reload"
								style="margin-left: 8px">重置</a-button>
						</span>
					</a-col>

				</a-row>
			</a-form>
		</div>
		<!-- 查询区域-END -->
		<a-table ref="table" size="middle" :scroll="{x:true}" bordered rowKey="id" :columns="columns"
			:dataSource="dataSource" :pagination="ipagination" :loading="loading" class="j-table-force-nowrap"
			@change="handleTableChange">
			
			<template slot="action" slot-scope="text, record">
				<a @click="handleDetail(record,'detail')">查看评分明细</a>
			</template>
			
		</a-table>
		</div>
		<wt-supplier-modal ref="modalForm" @ok="modalFormOk"></wt-supplier-modal>
		<score-detail ref="modalForm2"  @ok="modalFormOk"></score-detail>
	</a-card>
</template>

<script>
	import {
		httpAction,
		getAction
	} from '@/api/manage'
	import '@/assets/less/TableExpand.less'
	import {
		mixinDevice
	} from '@/utils/mixin'
	import {
		JeecgListMixin
	} from '@/mixins/JeecgListMixin'
	import WtSupplierModal from './modules/WtSupplierModal'
	import ScoreDetail from './components/ScoreDetail.vue'
	export default {
		name: 'WtSupplierList',
		mixins: [JeecgListMixin, mixinDevice],
		components: {
			WtSupplierModal,
			ScoreDetail
		},
		data() {
			return {
				description: '供应商管理页面',
				// 表头
				columns: [{
						title: '公司名称',
						align: "center",
						dataIndex: 'rateeName',
					},
					{
						title: '类型',
						align: 'center',
						dataIndex: 'rateeType',
						customRender: function(text, r, index) {
							return text === '1'?'供应商':text === '2'?'班组':text === '3'?'采购商':''
						}
					},
					{
						title: '最新评分时间',
						align: 'center',
						dataIndex: 'createTime',
					},
					{
						title: '最新评分',
						align: 'center',
						dataIndex: 'latestScore',
					},
					{
						title: '操作',
						dataIndex: 'action',
						align: 'center',
						fixed: 'right',
						width: 147,
						scopedSlots: {
							customRender: 'action'
						},
					},
				],
				url: {
					list: '/score/wtScoreRecord/list',
					delete: '',
					deleteBatch: '',
					exportXlsUrl: '',
					importExcelUrl: '',
				},
				dictOptions: {},
				statusList: [{
					label: '供应商',
					value: '1'
				}, {
					label: '班组',
					value: '2'
				}],
				model:{
					orgCode:'',
				}
			}
		},
		created() {
			
		},
		computed: {
			importExcelUrl: function() {
				return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
			},
		},
		methods: {
			handleDetail(record,type){
				this.$refs.modalForm2.title = '评分明细';
				this.$refs.modalForm2.disableSubmit = true;
				this.$refs.modalForm2.pageType = type;
				this.$refs.modalForm2.edit(record);
			},
			onChange(record) {
				console.log(1, record)
			},
			handleScore(record, type) {
				if (type === 'supplieredit') {
					this.$refs.modalForm2.title = '修改评分';
					this.$refs.modalForm2.disableSubmit = false;
				} else if (type === 'supplierdetail') {
					this.$refs.modalForm2.title = '评分记录';
					this.$refs.modalForm2.disableSubmit = true;
				}
				this.$refs.modalForm2.pageType = type;
				this.$refs.modalForm2.edit(record);
			},
			loadData(arg) {
				if (!!window.localStorage.getItem("pro__Login_Userinfo")) {
				  let userInfo = JSON.parse(window.localStorage.getItem("pro__Login_Userinfo")).value;
				  this.model.orgCode = userInfo.orgCode;
				}
				
				if (!this.url.list) {
					this.$message.error("请设置url.list属性!")
					return
				}
				//加载数据 若传入参数1则加载第一页的内容
				if (arg === 1) {
					this.ipagination.current = 1;
				}
				var params = this.getQueryParams(); //查询条件
				params.valuatorType = '2';
				params.valuatorId = this.model.orgCode;
				this.loading = true;
				getAction(this.url.list, params).then((res) => {
					if (res.success) {
						//update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
						this.dataSource = res.result.records || res.result;
						if (res.result.total) {
							this.ipagination.total = res.result.total;
						} else {
							this.ipagination.total = 0;
						}
						//update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
					} else {
						this.$message.warning(res.message)
					}
				}).finally(() => {
					this.loading = false
				})

			},
		},
	}
</script>
<style scoped>
	@import '~@assets/less/common.less';
</style>